﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialShare.Web.Integrations;
using SocialShare.BLL;
using System.Configuration;
using SocialShare.DAL.Facades;
using SocialShare.BusinessEntities;
using System.Web.UI.HtmlControls;

namespace SocialShare.Web.My_Account
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void odsUserProfile_Updated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            ConfigReader configReader = new ConfigReader();
            divMessage.Visible = true;
            if (e.Exception==null)
            {
                lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.OPERATION_SUCCESS.ToString());
                divMessage.Attributes.Add("class", "success");
            }
            else
            {
                lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.OPERATION_FAILED.ToString());
                divMessage.Attributes.Add("class", "error");
            }
           
        }

        protected void odsUserProfile_Updating(object sender, ObjectDataSourceMethodEventArgs e)
        {
            MemberFacade facade = new MemberFacade();
            HtmlInputText BlogNameTextBox = frvUserProfile.FindControl("BlogNameTextBox") as HtmlInputText;
            SocialShare_MemberProfiles profiles = facade.GetMemberByBlogName(BlogNameTextBox.Value.Trim(), Convert.ToInt32(frvUserProfile.DataKey["ProfileId"]));
            if (profiles != null)
            {
                e.Cancel = true;
                ConfigReader configReader = new ConfigReader();
                lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.BLOG_NAME_EXISTS.ToString());
                divMessage.Attributes.Add("class", "error");
            }
        }

        
    }
}